package com.yuan.fullstackback.service.impl;

import com.yuan.fullstackback.mapper.SysCategoryMapper;
import com.yuan.fullstackback.pojo.SysCategory;
import com.yuan.fullstackback.service.ISysCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 文章分类 业务层处理
 */
@Service
public class SysCategoryServiceImpl implements ISysCategoryService {

    @Autowired
    private SysCategoryMapper categoryMapper;

    /**
     * 检查分类表是否有数据
     */
    @Override
    public int checkCategoryCount() {
        return categoryMapper.checkCategoryCount();
    }

    /**
     * 校验分类名称是否唯一
     *
     * @param categoryName 分类名称
     * @return 结果
     */
    @Override
    public int checkCategoryUnique(String categoryName) {
        int i = categoryMapper.checkCategoryUnique(categoryName);
        return categoryMapper.checkCategoryUnique(categoryName);
    }

    /**
     * 查询所有分类
     *
     * @return 结果
     */
    @Override
    public List<SysCategory> selectAllCategory() {
        return categoryMapper.selectAllCategory();
    }

    /**
     * 根据Id查询分类信息
     *
     * @param categoryId 分类Id
     */
    @Override
    public boolean checkCategoryById(Long categoryId) {
        return categoryMapper.checkCategoryById(categoryId);
    }

    /**
     * 添加分类信息
     *
     * @param sysCategory 分类信息
     */
    @Override
    @Transactional
    public int insertCategory(SysCategory sysCategory) {
        return categoryMapper.insertCategory(sysCategory);
    }

    /**
     * 修改分类信息
     *
     * @param sysCategory 分类信息
     */
    @Override
    @Transactional
    public int updateCategory(SysCategory sysCategory) {
        return categoryMapper.updateCategory(sysCategory);
    }

    /**
     * 删除分类信息
     *
     * @param categoryId 分类Id
     */
    @Override
    @Transactional
    public int deleteCategoryById(Long categoryId) {
        return categoryMapper.deleteCategoryById(categoryId);
    }

    /**
     * 检查分类下是否存在文章
     *
     * @param categoryId 分类Id
     */
    @Override
    public int checkCategoryExistArticle(Long categoryId) {
        return categoryMapper.checkCategoryExistArticle(categoryId);
    }

}
